export default class Colors {
  static colorPrimary = 'rgba(255,2,2,0.77)';
  static colorLight = 'rgba(250,29,29,0.77)';
  static colorGrey = 'rgba(228,30,30,0.2)';
  static pageBg = '#ffffff';
  /**
   * 十六进制颜色值转为带透明度的颜色
   * @param _color 十六进制颜色
   * @param _opacity 透明度
   * @returns {string} rgba
   */

  static hexToRGBA =  function(_color, _opacity) {
    var sColor = _color.toLowerCase();
    //十六进制颜色值的正则表达式
    var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
    // 如果是16进制颜色
    if (sColor && reg.test(sColor)) {
      if (sColor.length === 4) {
        var sColorNew = "#";
        for (var i = 1; i < 4; i += 1) {
          sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
        }
        sColor = sColorNew;
      }
      //处理六位的颜色值
      var sColorChange = [];
      for (var i = 1; i < 7; i += 2) {
        sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
      }
      return "rgba(" + sColorChange.join(",") + "," + _opacity + ")";
    }
    return sColor;
  }
}

